﻿using System.ServiceModel;
using System.ServiceModel.Web;
using Interscape.TwilioClient.Components;

namespace Interscape.TwilioClient
{

    #region Service Interface

    [ServiceContract]
    public interface IRecordingManager
    {
        [OperationContract]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.WrappedResponse,
            ResponseFormat = WebMessageFormat.Xml,
            UriTemplate = "/Accounts/{accountSid}/Recordings"
            )]
        RecordingList GetAll(string accountSid);

        [OperationContract]
        [WebGet(
            BodyStyle = WebMessageBodyStyle.WrappedResponse,
            ResponseFormat = WebMessageFormat.Xml,
            UriTemplate = "/Accounts/{accountSid}/Recordings/{recordingSid}.xml"
            )]
        Recording Get(string accountSid, string recordingSid);

        [OperationContract]
        [WebInvoke(
            Method = "DELETE",
            BodyStyle = WebMessageBodyStyle.WrappedResponse,
            ResponseFormat = WebMessageFormat.Xml,
            UriTemplate = "/Accounts/{accountSid}/Recordings/{recordingSid}"
            )]
        void Delete(string accountSid, string recordingSid);

    }

    #endregion

    public class RecordingManager : ManagerBase<IRecordingManager>, IRecordingManager
    {

        #region Constructors

        /// <summary>
        /// Creates a new instance of the CallManager.
        /// </summary>
        /// <param name="accountSid">The 34 character string that uniquely identifies the Account which will be used to make the TwilioAPI requests.</param>
        /// <param name="authToken">The "password" for your Twilio API calls.</param>
        public RecordingManager(string accountSid, string authToken) : base(accountSid, authToken)
        {
        }

        #endregion

        /// <summary>
        /// Returns a list of Recordings, each representing a recording generated by your account.
        /// </summary>
        /// <returns>A RecordingList</returns>
        public RecordingList GetAll()
        {
            return this.GetAll(this.AccountSid);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="accountSid">A 34 character string that uniquely identifies the Account associated with this resource.</param>
        /// <returns></returns>
        public RecordingList GetAll(string accountSid)
        {
            return this.Channel.GetAll(accountSid);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="recordingSid"></param>
        /// <returns></returns>
        public Recording Get(string recordingSid)
        {
            return this.Get(this.AccountSid, recordingSid);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="accountSid">A 34 character string that uniquely identifies the Account associated with this resource.</param>
        /// <param name="recordingSid"></param>
        /// <returns></returns>
        public Recording Get(string accountSid, string recordingSid)
        {
            return this.Channel.Get(accountSid, recordingSid);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="recordingSid"></param>
        public void Delete(string recordingSid)
        {
            this.Delete(this.AccountSid, recordingSid);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="accountSid">A 34 character string that uniquely identifies the Account associated with this resource.</param>
        /// <param name="recordingSid"></param>
        public void Delete(string accountSid, string recordingSid)
        {
            this.Channel.Delete(accountSid, recordingSid);
        }

    }
}
